
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        4/20/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteVisitorDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteVisitorDAL
    {
        #region  Properties
		 
		public static string FIELD_ID = "ID";  
		public static string FIELD_COUNT = "Count";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteVisitor
        /// </summary>
        /// <param name="ID">Primary Keys</param>
        /// <returns>Collection of websiteVisitorInfo</returns>
        public static websiteVisitorInfo SelectOne(int ID)
        {
            websiteVisitorInfo _websiteVisitorInfo = new websiteVisitorInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteVisitorSelectOne", ID);
                if (dr.Read())
                    setwebsiteVisitorInfo(dr, ref _websiteVisitorInfo);
                return _websiteVisitorInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteVisitor
        /// </summary>
        /// <returns>Collection of websiteVisitorInfo</returns>
        public static List<websiteVisitorInfo> SelectAll()
        {
            List<websiteVisitorInfo> lstwebsiteVisitor = new List<websiteVisitorInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteVisitorSelectAll");
                setListwebsiteVisitorInfo(ref dr, ref lstwebsiteVisitor);
                return lstwebsiteVisitor;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteVisitornfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteVisitorInfo</returns>
        public static List<websiteVisitorInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteVisitorInfo> lstwebsiteVisitor = new List<websiteVisitorInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteVisitorSelectByFilters");
                setListwebsiteVisitorInfo(ref dr, ref lstwebsiteVisitor);
                return lstwebsiteVisitor;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteVisitor
        /// </summary>
        /// <param name="websiteVisitorInfo">Entity of websiteVisitor</param>
        /// <returns>error code</returns>
        public static int Insert(websiteVisitorInfo _websiteVisitorInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteVisitorInsert" 
											, _websiteVisitorInfo.Count
											, _websiteVisitorInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteVisitor
        /// </summary>
        /// <param name="websiteVisitorInfo">Entity of websiteVisitor</param>
        /// <returns>error code</returns>
        public static int Update(websiteVisitorInfo _websiteVisitorInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteVisitorUpdate"
											, _websiteVisitorInfo.ID
											, _websiteVisitorInfo.Count
											, _websiteVisitorInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="ID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int ID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteVisitorDelete", ID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        public static int UpdateCount()
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteVisitorUpdateCount");
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteVisitorInfo(ref SqlDataReader dr, ref List<websiteVisitorInfo> lstwebsiteVisitor)
        {
            websiteVisitorInfo _websiteVisitorInfo = null;
            while (dr.Read())
            {
                _websiteVisitorInfo = new websiteVisitorInfo();
                setwebsiteVisitorInfo(dr, ref _websiteVisitorInfo);
                lstwebsiteVisitor.Add(_websiteVisitorInfo);
            }
        }

        private static void setwebsiteVisitorInfo(SqlDataReader dr, ref websiteVisitorInfo _websiteVisitorInfo)
        {
			_websiteVisitorInfo.ID = dr[websiteVisitorDAL.FIELD_ID] != DBNull.Value ? Convert.ToInt32(dr[websiteVisitorDAL.FIELD_ID]) : 0;
			_websiteVisitorInfo.Count = dr[websiteVisitorDAL.FIELD_COUNT] != DBNull.Value ? Convert.ToString(dr[websiteVisitorDAL.FIELD_COUNT]) : string.Empty;
			_websiteVisitorInfo.Description = dr[websiteVisitorDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteVisitorDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteVisitor]";

        #endregion
    }
}

		